const {getConfigSingle} = require("../../api/api.js");
import Util from '../../utils/util.js';

const app = getApp()
Page({

  data: {
    iShidden: true,
    userInfo: [],
    options: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    that.setData({
      options: options
    })

    Util.chekWxLogin().then(res => {
      that.setData({
        userInfo: res.userInfo,
        iShidden: false
      })

      //接口获取链接
      if (!Util.isEmpty(that.options.type) && ['mini_tabbar_ppc', 'mini_tabbar_qrcode'].indexOf(that.options.type) != -1) {
        getConfigSingle({type: that.options.type}).then(res => {
          if (Util.isEmpty(res.data))
            return app.Tips({title: "数据错误"}, {tab: 3})
          that.setData({content_outside_link: res.data || ""})
        })
        return
      }
      that.initData();
    }).catch(errmsg => {
    })
  },
  initData() {
    let url = this.options.url || ''
    // url = "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzUzMDA2NzU4Mg==&scene=126"
    if (url == "wearticle") {  //发帖嘉宾文章
      let wearticle = wx.getStorageSync('wearticle');
      wearticle = wearticle ? JSON.parse(wearticle) : "";
      url = wearticle.link || ""

      wx.setNavigationBarTitle({
        title: wearticle.title || "发帖嘉宾",
      })
    }

    if (!url)
      return app.Tips({title: "链接地址不存在"}, {tab: 3})

    wx.setNavigationBarTitle({
      title: "本硕博联谊服务号",
    })

    this.setData({
      content_outside_link: url
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (e) {
    const is_refresh = wx.getStorageSync('is_refresh')
    if (is_refresh) {
      wx.removeStorageSync('is_refresh')
    }
  },

  bindSendDanmu() {
  },

  videoErrorCallback(e) {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})